package com.software.aperture.controller;



import antlr.StringUtils;
import com.software.aperture.bean.Photo;
import com.software.aperture.repository.PhotoRe;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@RestController
public class PhotoController {
    @Autowired
    private PhotoRe photoRe;
    private String pathphoto;
    private Photo Nowphoto;
    /**
     * 查询照片
     */
    @GetMapping(value = "/photos")
    public List<Photo> getPhotoPath()
    {
        System.out.println("ssss");
        return (photoRe.findAll());
    }
    /**
     * 获取图片url
     */
    @GetMapping(value = "/photourls")
    public List<String> getPhotoUrls() {
      List<Photo> list=photoRe.findAll();
    List<String> pathlist=new ArrayList<>();
    for(int i=0;i<list.size();i++)
        pathlist.add(list.get(i).getPhotopath());
    return pathlist;
    }
    /**
     * 通过图片类型查询
     */
    @GetMapping(value = "/photosbytype")
    public List<Photo> getPhotosByType(HttpServletRequest request)
    {
        String type=request.getParameter("InputType");
        return photoRe.findByphototype(type);
    }
    /**
     * 从前端获取当前图片路径
     */
    @PostMapping(value = "/photopath")
    public Boolean PhotoPath(HttpServletRequest request)
    {
        String id=request.getParameter("Nowpath");
        Photo photo=photoRe.findByphotoid(Integer.valueOf(id));
        pathphoto=photo.getPhotopath();
        System.out.println("dcj");
        Nowphoto=photo;
        return true;
    }
    /**
     * 返回当前图片url
     */
    @GetMapping(value = "/getnowpath")
    public Photo getnowpath()
    {
        return Nowphoto;
    }
    /**
     * 获取同类型图片
     */
    @GetMapping(value = "/getcomtype")
   public List<Photo> getComType(){
        return photoRe.findByphototype(Nowphoto.getPhototype());
    }
}
